#include "StdAfx.h"

#include "ImageExptLib.h"
#include "ProcParam.h"
#include "ProcParamInt.h"
#include "ProcParamDouble.h"
#include "ProcParamString.h"


ProcParam *ProcParam::CreateProcParam(const char *ParamType, const char *Name, int Index, IPluginICProcStepsParam::Direction dir, const char *Value)
{
	ProcParam *rc = '\0';

	if ((ParamType == '\0') || (Name == '\0') || (Index < 0) || (Value == '\0'))
		ImageExptLib::LogMsg("ProcParam::CreateProcParam", "ERROR: invalid input params; ParamType is %s, Name is %s, Index is %d, Value is %s", ((ParamType == '\0') ? "null" : "not null"), ((Name == '\0') ? "null" : "not null"), Index, ((Value == '\0') ? "null" : "not null"));
	else
	{
		std::string pType(ParamType );
		if (pType == IPluginICProcStepsParamDefIntP)
		{
			rc = new ProcParamInt(Index, Name, dir, atoi(Value));
		}
		else if (pType == IPluginICProcStepsParamDefDoubleP)
		{
			rc = new ProcParamDouble(Index, Name, dir, atof(Value));
		}
		else if (pType == IPluginICProcStepsParamDefStringP)
		{
			rc = new ProcParamString(Index, Name, dir, Value);
		}
		else
			ImageExptLib::LogMsg("ProcParam::CreateProcParam", "ERROR: invalid input params; ParamType is %s, Name is %s, Index is %d, Value is %s", ((ParamType == '\0') ? "null" : "not null"), ((Name == '\0') ? "null" : "not null"), Index, ((Value == '\0') ? "null" : "not null"));

		if (rc != '\0')
			rc->_valStr = Value;
	}
	return rc;
}

ProcParam *ProcParam::CreateProcParam(ProcParam* param)
{
	ProcParam *rc = '\0';

	if (param == '\0')
		ImageExptLib::LogMsg("ProcParam::CreateProcParam - copy", "ERROR: input param is null" );
	else
	{
		std::string pType(param->GetType());
		if (pType == IPluginICProcStepsParamDefIntP)
		{
			rc = new ProcParamInt((ProcParamInt *)(param));
		}
		else if (pType == IPluginICProcStepsParamDefDoubleP)
		{
			rc = new ProcParamDouble((ProcParamDouble *)(param));
		}
		else if (pType == IPluginICProcStepsParamDefStringP)
		{
			rc = new ProcParamString((ProcParamString *)(param));
		}
		else
			ImageExptLib::LogMsg("ProcParam::CreateProcParam", "ERROR: invalid input type"); 

		if (rc != '\0')
			rc->_valStr = param->_valStr;
	}
	return rc;
}

ProcParam::ProcParam(const ProcParam* param) : 
	_refCnt(0),
	_dir(IPluginICProcStepsParam::input),
	_index(IPluginICProcStepsParam::Invalid),
	_name(IPluginICProcStepsParamBadName),
	_valStr(IPluginICProcStepsParamBadValue),
	_error(true)
{
	if (param == '\0')
		ImageExptLib::LogMsg("ProcParam::ProcParam() copy ctor", "ERROR: param is null");
	else
	{
		_dir = param->_dir;
		_index = param->_index;
		_name = param->_name;
		_valStr = param->_valStr;
		_error = param->_error;
	}
}

ProcParam::ProcParam() :
	_refCnt(0),
	_dir(IPluginICProcStepsParam::input),
	_index(IPluginICProcStepsParam::Invalid),
	_name(IPluginICProcStepsParamBadName),
	_valStr(IPluginICProcStepsParamBadValue),
	_error(true)
{

}

ProcParam::ProcParam(int Index, const char *Name, IPluginICProcStepsParam::Direction dir ) :
	_refCnt(0),
	_index((Index >= 0) ? Index : IPluginICProcStepsParam::Invalid),
	_name((Name != '\0') ? Name : IPluginICProcStepsParamBadName),
	_dir(dir),
	_valStr(IPluginICProcStepsParamBadValue),
	_error( (((_index ==  IPluginICProcStepsParam::Invalid) || (_name == IPluginICProcStepsParamBadName)) ? true : false) )
{

}

ProcParam::~ProcParam(void)
{
	_error = false;
}

bool ProcParam::IsValid()
{ 
	return ((_error == false) ? true: false); 
}

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------

